package com.lgqz.himalayafm.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lgqz.himalayafm.R;
import com.lgqz.himalayafm.bean.RadioEntity;

import java.util.List;

/**
 * Created by Administrator on 2016/12/5/005.
 */

public class RadioSeconListAdapter extends BaseAdapter {
    private Context context;
    private List<RadioEntity.RadiotopRadiosEntity> radiotopRadiosEntityList;

    public RadioSeconListAdapter(Context context, List<RadioEntity.RadiotopRadiosEntity> radiotopRadiosEntityList) {
        this.context = context;
        this.radiotopRadiosEntityList = radiotopRadiosEntityList;
    }


    @Override
    public int getCount() {

        return radiotopRadiosEntityList.size();
    }

    @Override
    public Object getItem(int position) {
        return radiotopRadiosEntityList.get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodler hodler = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.fragment_radios_listview_item, parent, false);
            hodler = new ViewHodler(convertView);
            convertView.setTag(hodler);
        } else {
            hodler = (ViewHodler) convertView.getTag();
        }
        hodler.fristStationname.setText(radiotopRadiosEntityList.get(position).getName());
        hodler.fristPeoplenum.setText(radiotopRadiosEntityList.get(position).getPlayCount());
        hodler.fristnowStation.setText("正在直播：" + radiotopRadiosEntityList.get(position).getProgramName());
        hodler.fristlistImage.setImageURI(radiotopRadiosEntityList.get(position).getCoverSmall());
        return convertView;
    }

    public static class ViewHodler {

        private final SimpleDraweeView fristlistImage;
        private final TextView fristStationname;
        private final TextView fristnowStation;
        private final TextView fristPeoplenum;
        private final ImageView fristlistplay;

        public ViewHodler(View view) {
            fristlistImage = (SimpleDraweeView) view.findViewById(R.id.radio_listimage_id);
            fristStationname = (TextView) view.findViewById(R.id.radio_liststation_name_id);
            fristnowStation = (TextView) view.findViewById(R.id.radio_fristlist_user);
            fristPeoplenum = (TextView) view.findViewById(R.id.radio_list_people_num);
            fristlistplay = (ImageView) view.findViewById(R.id.radio_frist_play);
        }
    }
}
